TK!2
=v
=u
=l
#1
:n
u
:v
'u1
'u2
'u3
'u4
'u5
'u6
'u7
'u8
'u9
'u10
E
#2
:n
u1
:v
1
2
3
E
#3
:n
u2
:v
0
1
2
E
#4
:n
u3
:v
-1
0
1
E
#5
:n
u4
:v
-2
-1
0
E
#6
:n
u5
:v
E
#7
:n
u6
:v
E
#8
:n
u7
:v
E
#9
:n
u8
:v
E
#10
:n
u9
:v
E
#11
:n
u10
:v
E
#12
:n
v
:v
'v1
'v2
'v3
'v4
'v5
'v6
'v7
'v8
'v9
'v10
E
#13
:n
v1
:v
0
-1
-2
-3
E
#14
:n
v2
:v
1
0
-1
-2
E
#15
:n
v3
:v
2
1
0
-1
E
#16
:n
v4
:v
E
#17
:n
v5
:v
E
#18
:n
v6
:v
E
#19
:n
v7
:v
E
#20
:n
v8
:v
E
#21
:n
v9
:v
E
#22
:n
v10
:v
E
#23
:n
w
:v
'w1
'w2
'w3
'w4
'w5
'w6
'w7
'w8
'w9
'w10
E
#24
:n
w1
:v
E
#25
:n
w2
:v
E
#26
:n
w3
:v
E
#27
:n
w4
:v
E
#28
:n
w5
:v
E
#29
:n
w6
:v
E
#30
:n
w7
:v
E
#31
:n
w8
:v
E
#32
:n
w9
:v
E
#33
:n
w10
:v
E
=f
#1
:n
Msum
:c
Adding two matrices
:t
Procedure
:i
A,B,C
#2
:n
Mblank
:c
Blank matrix (i.e. subordinate lists)
:t
Procedure
:i
M,n
#1
:n
Msum
:z
" The procedure generates a sum of two matrices defined by the master lists 
" A  and  B  and their subordinate lists.  The resulting matrix is stored
" in lists subordinate to the master list C, which must be set up in advance.
" The master list  C  must be long enough to accommodate the last non-empty
" row-lists in  A  and  B . 

" Strictly speaking, the matrices  A  and  B  should have the same numbers
" of rows and columns.  The procedure  Msum  is more generous: it accepts
" different  mA x nA  and  mB x nB , and generates resulting matrix with
" max(mA,mB) x max(nA,nB)  rows and columns.  Blank or missing coefficients
" in matrix  A  and  B  are assumed to be zeros.

" Supporting function : Mblank

n:= 1
'aux[1]:= 0
for a=1 to length(A)
   if length(A[a])=0 goto nexta
   ma:= a
   n:= max(n,length(A[a]))
nexta: next a
for b=1 to length(B)
   if length(B[b])=0 goto nextb
   mb:= b
   n:= max(n,length(B[b]))
nextb: next b
m:= max(ma,mb)
call Mblank(C,m)   " error indicates insufficient length of master list C
for i=1 to m
   Ai:= elt(A,i,'aux)
   Bi:= elt(B,i,'aux)
   Ci:= C[i]
   for j=1 to n
      Ci[j]:= elt(Ai,j,0) + elt(Bi,j,0)
   next j
next i
call delete('aux)
/E
E
#2
:n
Mblank
:z
" The procedure blanks (i.e. erases the contents) of the first  n  lists
" named in the master list  M .

for i=1 to n
   call blank(M[i])    " error indicates no listname in ith element of M
next i
/E
E
=r
#1
:r
call Msum('u,'v,'w)             " ***  Matrix  Summation  ***
#3
:r
" This is an example of using a library function Msum for adding two
:s
C
#4
:r
" matrices  u  and  v , and storing the result in  w .  
:s
C
#5
:r
" Press F9 and watch the result come up in the lower window.
:s
C
#7
:r
" The matrices  u  and  v  may be displayed as tables with the same names, 
:s
C
#8
:r
" and altered as required.
:s
C
=p
=t
#1
:n
u
:s
Screen
:v
Horizontal
:f
1
:r
""
:c
""
:t
"Input matrix u"
:u
#1
:l
u1
:w
8
:h
""
#2
:l
u2
:w
8
:h
""
#3
:l
u3
:w
8
:h
""
#4
:l
u4
:w
8
:h
""
E
#2
:n
v
:s
Screen
:v
Horizontal
:f
1
:r
""
:c
""
:t
"Input matrix v"
:u
#1
:l
v1
:w
8
:h
""
#2
:l
v2
:w
8
:h
""
#3
:l
v3
:w
8
:h
""
E
#3
:n
w
:s
Screen
:v
Horizontal
:f
1
:r
""
:c
""
:t
"Sum of matrices  u  and  v"
:u
#1
:l
w1
:w
8
:h
""
#2
:l
w2
:w
8
:h
""
#3
:l
w3
:w
8
:h
""
#4
:l
w4
:w
8
:h
""
E
#4
:s
Screen
:v
Vertical
:f
1
:r
""
:c
""
:t
""
:u
E
=n
=g
#1
:c
.000001
:i
10
:v
Yes
:l
60
:f
66
:m
0
:w
80
:b
Yes
:a
Yes
:r
Yes
:h
No
:t
1
:n
Yes
:d
LPT1
%Tr,f,0,1,0,1,0
%Ot,f,2,1,0,1,0>t,0,0,0,8,0>f,0,1,0,2,0
